/**
 * Copyright (c) 2010 sonntagsfarben.de
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package de.sonntagsfarben.puremvc.as3.mediator 
{
	import de.sonntagsfarben.puremvc.as3.mediator.CoreMediator;
	import de.sonntagsfarben.puremvc.as3.proxy.SWFAddressProxy;
	import de.sonntagsfarben.view.CoreView;

	import org.puremvc.as3.multicore.interfaces.IMediator;

	/**
	 * @author Soenke Kluth <kluth@sonntagsfarben.de>
	 */
	public class SectionMediator extends CoreMediator 
	{

		/*
		 * sectionmediator. mostly used as ApplicationMediator for websites with swfaddress
		 * register/remove mediators
		 * adding the content depending on witch section is selected.
		 * waiting for intro and outro of AbstractView
		 */

		private const NULLSECTION : String = "%%%";
		private var _currentSection : String = NULLSECTION;

		private var _currentMediator : IMediator;
		private var _currentView : CoreView;

		private var _queuedMediator : IMediator;
		private var _queuedView : CoreView;

		public function SectionMediator(name : String = null, viewComponent : Object = null)
		{
			super(name, viewComponent);
		}

		
		
		protected function handleSectionChange() : void
		{
			var swfAddressProxy : SWFAddressProxy = facade.retrieveProxy(SWFAddressProxy.NAME) as SWFAddressProxy;
			var uriSegments : Array = swfAddressProxy.addressSegments;
			
			var section : String = uriSegments[0];
			
			if(section == _currentSection)
				return;
			
			
			switch(section) {
//				case Constants.SECTION_HOME.url:
//					queuedView = new HomeView();
//					queuedMediator = new HomeMediator(queuedView as HomeView);
//					break;
							
				default:
					//SECTION IS NOT VALID
					return;
					break;
			}
					
			if(_currentView) {
				//_currentView.addEventListener(AbstractView.OUTRO_COMPLETE, onOutroComplete);
				_currentView.transitionOut();
			}
					
			//abfragen ob noch getweent wird:: oink::
			// app startet zum ersten mal
			if(_currentSection == NULLSECTION) {
						//addView();
					}
					
			_currentSection = section;
		}
	}
}
